package cn.sypt.yuhao.servlet;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;

import cn.sypt.yuhao.domain.Manager;
import cn.sypt.yuhao.domain.User;

/**
 * Servlet Filter implementation class JspFilter
 */

public class JspFilter implements Filter {

	/**
	 * Default constructor.
	 */
	public JspFilter() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see Filter#destroy()
	 */
	public void destroy() {
		// TODO Auto-generated method stub
	}

	/**
	 * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
	 */
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		/*// TODO Auto-generated method stub
		// place your code here
		HttpServletRequest httprequest = (HttpServletRequest) request;
		// pass the request along the filter chain
		User user = (User) httprequest.getSession().getAttribute("user");
		Manager man = (Manager) httprequest.getSession().getAttribute("man");
		System.out.println("userfilter" + user);
		System.out.println("manfilter" + man);
		if (user != null) {
			httprequest.setAttribute("msg", "请不要非法访问!");
			httprequest.getRequestDispatcher("/ui/msg.jsp").forward(
					httprequest, response);
			chain.doFilter(request, response);
		} else {

			httprequest.setAttribute("msg", "请不要非法访问!");
			httprequest.getRequestDispatcher("/ui/msg.jsp").forward(
					httprequest, response);
			// chain.doFilter(request, response);
		}
		if (man != null) {
			chain.doFilter(request, response);
		} else {
			httprequest.setAttribute("msg", "请不要非法访问!");
			httprequest.getRequestDispatcher("/ui/msg.jsp").forward(
					httprequest, response);
			chain.doFilter(request, response);
		}
*/
		chain.doFilter(request, response);
	}

	/**
	 * @see Filter#init(FilterConfig)
	 */
	public void init(FilterConfig fConfig) throws ServletException {
		// TODO Auto-generated method stub
	}

}
